package com.biao.java8.demo;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

public class TestSimpleDateFormat {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");

        // 测试之前的多线程情况下会出现异常
        Callable<Date> call = new Callable<Date>() {

            @Override
            public Date call() throws Exception {
                return simpleDateFormat.parse("20210919");
            }
        };

        ExecutorService pool = Executors.newFixedThreadPool(10);

        List<Future<Date>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(pool.submit(call));
        }
        for (Future<Date> future : futures) {
            System.out.println(future.get());
        }
    }
}
